package persistence;

import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class DBCPoolingListener implements ServletContextListener {
	public void contextInitialized (ServletContextEvent sce)
	{
		try {
			// Obtain our environment naming context
			Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
			// Look up our data source
			DataSource  ds = (DataSource) envCtx.lookup("jdbc/a1006529");
			sce.getServletContext().setAttribute("DBCPool", ds);
		} 
		
		catch(NamingException e)
		{ e.printStackTrace(); }
	}
	
	public void contextDestroyed(ServletContextEvent sce)
	{}
}